﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using ZSZ.Core.Entities;

namespace ZSZ.EntityFramework.ModelConfig
{
    class CommunityConfig: EntityTypeConfiguration<CommunityEntity>
    {

        public override void Map(EntityTypeBuilder<CommunityEntity> builder)
        {
            builder.ToTable("T_Community");
            //Community必须有Region，一个Region有很多的Community，他们使用RegionId做外键
            builder.HasOne(e => e.Region).WithMany().HasForeignKey(e => e.RegionId)
                .OnDelete(DeleteBehavior.ClientSetNull);
            builder.Property(e => e.Location).HasMaxLength(1024).IsRequired();
            builder.Property(e => e.Name).HasMaxLength(20).IsRequired();
        }
    }
}
